//
//  Status.swift
//  weibo
//
//  Created by 谭仁川 on 15/12/1.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class Status: NSObject {
    var created_at: String?
    
    var id: Int = 0
    
    var text: String?
    
    var source: String?
    
    var user: User?
    
    //被转发微博字段
    var retweeted_status: Status?
    
    var pic_urls: [[String : String]]? {
        didSet {
        
            guard let urls = pic_urls else{
                return
            }
            imageURLs = [NSURL]()
            for item in urls {
                let urlString = item["thumbnail_pic"]
                
                let url = NSURL(string: urlString!)!
                imageURLs?.append(url)
            }
        }
    }
    
    var imageURLs: [NSURL]?
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
        if let dict = value as? [String : AnyObject]{
            user = User(dict: dict)
        }
        return
    }
        if key == "retweeted_status" {
            if let dict = value as? [String : AnyObject]{
                retweeted_status = Status(dict: dict)
            }
            return
        }

        super.setValue(value, forKey: key)
 }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }
    override var description: String {
        let keys = ["created_at","id","text","source"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
}
